// pages/PubPage/PubPage.js
var api = require("../../utils/request.js");
var screenUtil = require("../../utils/screen.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.showShareMenu({
      // 要求小程序返回分享目标信息
      withShareTicket: true
    }); 
    var screen = screenUtil.screenUtil()
    var scrHeight = screen.windowHeight
    console.log("getApp().globalData.windowHeight====",getApp().globalData.windowHeight)
    this.setData({
      screenheight:scrHeight,
      scrWidth: screen.windowWidth,
      isIphoneX: getApp().globalData.statusBarHeight>=44?true:false,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    wx.hideHomeButton();
    const obj = wx.getEnterOptionsSync()
    wx.setStorageSync('targetId', obj.query.id)
    wx.setStorageSync('leaderId', obj.query.userId)
    wx.setStorageSync('title', obj.query.title)
    wx.setStorageSync('bitmap', obj.query.bitmap)

    that.setData({
      title:wx.getStorageSync('title'),
      bitmap:wx.getStorageSync('bitmap')
    })

    api.request1({"path": "user/tuangouGDFW","tuangouId":wx.getStorageSync("targetId")}, function (result) {  

      if(result.code=='0'){

        wx.setClipboardData({
          data: result.msg,
        })
      }
    }, function (error) {
    })


  },
  shareMessage:function(){
    this.onShareAppMessage()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this
    // wx.showToast({
    //   title: 'id='+wx.getStorageSync('targetId'),
    // })
    // if (ops.from === 'button') {
    //   // 来自页面内转发按钮
    //   console.log(ops.target)
    // }
    return {
      title: wx.getStorageSync('title'),
      imageUrl:  wx.getStorageSync('bitmap'),
      path: '/pages/HomePage/HomePage?id=' + wx.getStorageSync('targetId')+'&userId='+ wx.getStorageSync('leaderId'), 
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }

  }
})